<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px"  class="demo-ruleForm">
    <el-form-item label="班级名称" prop="planName">
      <el-input v-model="ruleForm.planName" style="width: 300px"></el-input>
    </el-form-item>
    <el-form-item label="负责人工号" prop="principalName">
      <el-input v-model="ruleForm.principalName" style="width: 300px"></el-input>
    </el-form-item>
    <el-form-item label="培训计划选择" prop="planIntro">
      <el-select v-model="svalue" filterable placeholder="请选择" style="width: 300px">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="学员选择" prop="courseSelect">
      <div class="edit_dev">
      <el-transfer
        filterable
        :filter-method="filterMethod"
        filter-placeholder="请输入学员工号"
        v-model="value"
        :data="data"
        :titles="['待选学员','已选学员']">
      </el-transfer>
      </div>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
    import {validateChinese} from "../../tools/validate";

    export default {
        name: "AddTrainClass",
      //生成未选择的数据
      data() {
          //选择器数据项

        //穿梭框的数据项
        const generateData = _ => {
          const data = [];
          for (let i = 1; i <= 15; i++) {
            data.push({
              key: i,
              label: `学员编号 ${ i },学员名字`,
            });
          }
          return data;
        };

        return {
          //选择器数据项
          options: [{
            value: '选项1',
            label: '黄金糕'
          }, {
            value: '选项2',
            label: '双皮奶'
          }, {
            value: '选项3',
            label: '蚵仔煎'
          }, {
            value: '选项4',
            label: '龙须面'
          }, {
            value: '选项5',
            label: '北京烤鸭'
          }],
          svalue: '',
          //表单的各个数据项的值
          ruleForm: {
            planName:'',
            principalName:'',
            planIntro:'',

          },
          //穿梭框存放未选择的数据
          data: generateData(),
          //穿梭框存放选择课程的数据
          value:[],
          rules: {
            planName: [
              { required: true, message: '请输入计划名称', trigger: 'blur' },
              { min: 0, max: 15, message: '长度在 0 到 15 个字符', trigger: 'blur' },
            ],
            principalName: [
              { required: true, message: '请输入负责人名称', trigger: 'blur' },
              { min: 0, max: 8, message: '长度在 0 到 8 个字符', trigger: 'blur' },
              {validator:validateChinese,trigger: 'blur'}

            ],
            planIntro:[
              { required: true, message: '请输入负责人简介', trigger: 'blur' },
            ],
          },

        };
      },
      methods: {
        //表单提交
        submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              alert('submit!');
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        //重置表单数据
        resetForm(formName) {
          this.$refs[formName].resetFields();
        },



      }
    }
</script>

<style scoped>
  .edit_dev >>> .el-transfer-panel {
    width:350px;
  }
</style>
